<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * User: mmfffzzzz
 * Date: 14-3-28
 * Time: 下午12:14
 */


class Feedback extends Base_Controller {


    public function __construct()
    {

        parent::__construct();
        $this->load->model('sys_user_model');
        //$this->load->model('sys_user_group_model');

    }

	public function index()
	{
		$_like = array();
        $_where = array();
        $_order_by = array('fd_id' => 'desc');

        $title = $this->input->get_post('title');
        $type = $this->input->get_post('type');

        if(notBlank($title)){
            $_like['title'] = $title;
        }
        if(notBlank($type)){
            $_where['type'] = $type;
        }
        $this->sys_user_model->_table="xq_feedback";
        $page = $this->sys_user_model->getListByPage($this->page_offset, $_where, $_like, $_order_by,
        array("*"),
            array(
            ));
        $this->put("pagerbar", $this->getPageBar('index.php', $page['total']));
        $this->put("tname", array("1"=>'投诉','2'=>'反馈','3'=>'报修'));
        $this->put("list", $page['list']);
        $this->put("title", $title);
        $this->put("type", $type);
		$this->render('feedback_list.html');
	}

    public function add()
    {
        if(IS_POST){

            $_data = $this->parseData(array('article_url','article_show','article_sort','article_title','article_content',"article_time"));
            $_data['article_time']=date("Y-m-d H:i:s",time());
            //print_r($_data);exit;
            //$_data['id'] = get_rnd_id();
            //$_data['password'] = get_password($this->input->post('password'),$_data['id']);
        	$this->sys_user_model->_table="xq_feedback";
            $this->handleResult($this->sys_user_model->addEntity($_data));


        }
        //$this->put("group_list",$this->sys_user_group_model->getSysGroupArray());
        $this->render('feedback_edit.html');
    }
    public function edit()
    {
        $_id = $this->input->get('id');
        if(IS_POST){
            $_data = $this->parseData(array('article_url','article_show','article_sort','article_title','article_content',"article_time"));
        	$this->sys_user_model->_table="xq_feedback";
            $this->handleResult($this->sys_user_model->updateEntityByID($_data,$_id,"fd_id"));
        }
        $this->sys_user_model->_table="xq_feedback";
        $this->put('entity',$this->sys_user_model->getEntityByID($_id,array("*"),"fd_id"));
        $this->render('user_edit.html');
    }

    public function delete()
    {
        $_id = $this->input->get('id');
        $this->sys_user_model->_table="xq_feedback";
        echo $this->sys_user_model->deleteEntityByID($_id,"fd_id")?STATUS_SUCCESS:STATUS_ERROR;
    }

    public function status(){
        $_id = $this->input->get('id');
        $_status = $this->input->get('status');
        $_data['states'] = $_status;
        $this->sys_user_model->_table="xq_feedback";
        echo $this->sys_user_model->updateEntityByID($_data,$_id,"fd_id")?STATUS_SUCCESS:STATUS_ERROR;
    }

}

